package com.carrental.vehicle.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carrental.common.result.Result;
import com.carrental.vehicle.entity.VehicleSeries;
import com.carrental.vehicle.service.VehicleSeriesService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆系列控制器
 */
@Api(tags = "车辆系列管理")
@RestController
@RequestMapping("/vehicle-series")
@RequiredArgsConstructor
public class VehicleSeriesController {

    private final VehicleSeriesService vehicleSeriesService;

    @ApiOperation("根据ID获取系列")
    @GetMapping("/{id}")
    public Result<VehicleSeries> getSeriesById(
            @ApiParam("系列ID") @PathVariable Long id) {
        return Result.success(vehicleSeriesService.getSeriesById(id));
    }

    @ApiOperation("保存或更新系列")
    @PostMapping("/save")
    public Result<Boolean> saveOrUpdateSeries(
            @ApiParam("系列信息") @Validated @RequestBody VehicleSeries vehicleSeries) {
        return Result.success(vehicleSeriesService.saveOrUpdateSeries(vehicleSeries));
    }

    @ApiOperation("删除系列")
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteSeriesById(
            @ApiParam("系列ID") @PathVariable Long id) {
        return Result.success(vehicleSeriesService.deleteSeriesById(id));
    }

    @ApiOperation("分页查询系列")
    @GetMapping("/page")
    public Result<Page<VehicleSeries>> pageSeries(
            @ApiParam("页码") @RequestParam(defaultValue = "1") Integer current,
            @ApiParam("每页数量") @RequestParam(defaultValue = "10") Integer size,
            @ApiParam("品牌ID") @RequestParam(required = false) Long brandId,
            @ApiParam("系列名称") @RequestParam(required = false) String name) {
        Page<VehicleSeries> page = new Page<>(current, size);
        VehicleSeries series = new VehicleSeries();
        series.setBrandId(brandId);
        series.setName(name);
        return Result.success(vehicleSeriesService.pageSeries(page, series));
    }

    @ApiOperation("根据品牌ID获取系列列表")
    @GetMapping("/list/brand/{brandId}")
    public Result<List<VehicleSeries>> listSeriesByBrandId(
            @ApiParam("品牌ID") @PathVariable Long brandId) {
        return Result.success(vehicleSeriesService.listSeriesByBrandId(brandId));
    }

    @ApiOperation("根据品牌ID获取可用的系列列表")
    @GetMapping("/list/available/brand/{brandId}")
    public Result<List<VehicleSeries>> listAvailableSeriesByBrandId(
            @ApiParam("品牌ID") @PathVariable Long brandId) {
        return Result.success(vehicleSeriesService.listAvailableSeriesByBrandId(brandId));
    }
} 